﻿using HR.Config;
using HR.Filters;
using HR.IService;
using HR.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Collections;

namespace HR.Controllers
{
    public class SalaryStandardController : Controller
    {
        // 薪酬标准单接口
        private readonly ISalaryStandardService isss;
        // 薪酬标准单详细信息接口
        private readonly ISalaryStandardDetailService issds;
        //薪酬标准控制器
        public SalaryStandardController(ISalaryStandardService isss, ISalaryStandardDetailService issds)
        {
            this.isss = isss;
            this.issds = issds;
        }

        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 薪酬标准登记视图
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 查询所有薪酬组成
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryConst()
        {
            //薪资组成集合
            List<config_public_char> list = await isss.SalaryConst();
            //自动生成的最新薪酬标准编号
            string standard_id = await isss.FindNewStandard_id();
            Hashtable ht = new Hashtable();
            ht.Add("cities", list);
            ht.Add("standard_id", standard_id);
            return Json(ht);
        }
        /// <summary>
        /// 查询所有用户集合
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> FindUsers()
        {
            List<user> users = await isss.FindUsers();
            return Json(users);
        }
        /// <summary>
        /// 薪酬标准登记
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SalaryStandardAdd([FromBody] salary_standard ss)
        {
            //首先新增的薪资标准复核状态为0
            ss.check_status = 0;
            int res = await isss.SalaryStandardAdd(ss);
            return Json(res);
        }
        /// <summary>
        /// 薪酬标准详细信息登记
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryStandardDetailAdd(string strjson)
        {
            //string? aa= Request.Form["jsonstr"];
            List<salary_standard_detail>? list = JsonConvert.DeserializeObject<List<salary_standard_detail>>(strjson);
            int res = await issds.SalaryStandardDetailAdd(list);
            return Json(res);
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 薪酬标准登记复核视图
        /// </summary>
        /// <returns></returns>
        public IActionResult IndexCheck()
        {
            return View();
        }
        /// <summary>
        /// 查询所有薪酬标准信息，未复核过的
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> SalaryFillIsNoCheck(int pgsize,int pgcurrent)
        {
            Paging<salary_standard> pg = await isss.SalaryFillIsNoCheck(pgsize, pgcurrent);
            return Json(pg);
        }
        /// <summary>
        /// 薪酬标准单号查询所有详单的薪酬信息
        /// </summary>
        /// <param name="standard_id"></param>
        /// <returns></returns>
        public async Task<IActionResult> SalaryStandardDetailBySid(string standard_id)
        {
            List<salary_standard_detail> list = await issds.SalaryStandardDetailBySid(standard_id);
            return Json(list);
        }
        /// <summary>
        /// 薪酬标准登记复核小小修改一下
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SalaryStandardCheck([FromBody] salary_standard ss)
        {
            int res = await isss.SalaryStandardCheck(ss);
            return Json(res);
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 薪酬标准查询视图
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult IndexFind()
        {
            return View();
        }
        /// <summary>
        /// 薪酬标准模糊查询接口,查询的是未被复核过的薪酬标准
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SalaryStandardDimFind([FromBody] SalaryStandardDimPage ssdp)
        {
            Paging<salary_standard> pg = await isss.SalaryStandardDimFind(ssdp);
            return Json(pg);
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 薪酬标准变更视图
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult IndexUpdate()
        {
            return View();
        }
        /// <summary>
        /// 薪酬标准变更
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SalaryStandardUdp([FromBody] salary_standard ss)
        {
            int res = await isss.SalaryStandardUdp(ss);
            return Json(res);
        }
        /// <summary>
        /// 薪酬标准详情修改
        /// </summary>
        /// <param name="strjson"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryStandardDetailUdp(string strjson)
        {
            List<salary_standard_detail>? list = JsonConvert.DeserializeObject<List<salary_standard_detail>>(strjson);
            int res = await issds.SalaryStandardDetailUdp(list);
            return Json(res);
        }
        /// <summary>
        /// 根据档案ID查询到对应的薪酬标准，然后从薪酬标准查出明细
        /// </summary>
        /// <param name="human_id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryStandardDetailsFindHmid(string human_id)
        {
            List<salary_standard_detail> list = await issds.SalaryStandardDetailsFindHmid(human_id);
            return Json(list);
        }

    }
}
